/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:何人亮
 * Date:2024-05-08
 * 15:25
 */
public class Test {
    public static void main(String[] args) {
        int[] arr={1,2,3,4,5,6};
        System.out.println( fun(arr,6));
    }
    public static int fun(int[] arr,int x){
        int right=0;
        int left= arr.length-1;
        int mid=0;
        while (right<=left){
            mid=(right+left)/2;
            if(arr[mid]>x){
                left=mid-1;
            }
            if(arr[mid]<x){
                right=mid+1;
            }
            if(arr[mid]==x){
                break;
            }
        }
        return mid;
    }
}
